#include "CSetSpriteTextureCommand.h"
#include "CUserInterface.h"
#include "CLevelEditor.h"
#include "CAnimatedBillboardSceneNode.h"

extern CGlobals* g;
extern CUserInterface* ui;
extern CLevelEditor* editor;

CSetSpriteTextureCommand::CSetSpriteTextureCommand(int id, stringw newTextureFile)
{
	m_id = id;
	CSceneObject* obj = editor->getSceneObjectFromID(id);
	m_oldTextureFile = obj->m_UserData->getAttributeAsStringW("SpriteTexture");
	m_newTextureFile = newTextureFile;
	setDescription(L"change TextureFile");
}

void CSetSpriteTextureCommand::redo()
{
	CSceneObject* obj = editor->getSceneObjectFromID(m_id);
	obj->m_UserData->setAttribute("SpriteTexture", m_newTextureFile.c_str());
	(dynamic_cast<CAnimatedBillboardSceneNode*>(obj->m_SceneNode))->LoadTexture(stringc(m_newTextureFile.c_str()).c_str());
	editor->setSelectedNode(obj->m_SceneNode);
	ui->createSelectedObjectProperties();
}

void CSetSpriteTextureCommand::undo()
{
	CSceneObject* obj = editor->getSceneObjectFromID(m_id);
	obj->m_UserData->setAttribute("SpriteTexture", m_oldTextureFile.c_str());
	(dynamic_cast<CAnimatedBillboardSceneNode*>(obj->m_SceneNode))->LoadTexture(stringc(m_oldTextureFile.c_str()).c_str());
	editor->setSelectedNode(obj->m_SceneNode);
	ui->createSelectedObjectProperties();
}
